package com.aruba.paging.api;

import okhttp3.OkHttpClient;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

/**
 * Created by aruba on 2021/9/17.
 */
public class RetrofitClient {
    private static final String BASE_URL = "http://192.168.17.114:8080/pagingserver_war/";
    private static RetrofitClient instance = new RetrofitClient();
    private Retrofit retrofit;

    public static RetrofitClient getInstance() {
        if (instance == null) {
            instance = new RetrofitClient();
        }
        return instance;
    }

    private RetrofitClient() {
        retrofit = new Retrofit.Builder()
                .baseUrl(BASE_URL)
                .addConverterFactory(GsonConverterFactory.create())
                .client(getOkhttpClient())
                .build();
    }

    private OkHttpClient getOkhttpClient() {
        return new OkHttpClient.Builder().build();
    }

    public Api getApi() {
        return retrofit.create(Api.class);
    }
}
